﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using erpIngesup.Areas.Professeur.Models;

namespace erpIngesup.Areas.Professeur.Controllers
{
    public class EvaluationController : Controller
    {
        private bddIngesupEntitiesProfesseur db = new bddIngesupEntitiesProfesseur();

        //
        // GET: /Professeur/Evaluation/

        public ActionResult Index()
        {

            var evaluation = db.EVALUATION.Include("MODULE");
            return View(evaluation.ToList());
        }

        //
        // GET: /Professeur/Evaluation/Details/5

        public ActionResult Details(int id = 0)
        {
            EVALUATION evaluation = db.EVALUATION.Single(e => e.IDEVAL == id);
            if (evaluation == null)
            {
                return HttpNotFound();
            }
            return View(evaluation);
        }

        //
        // GET: /Professeur/Evaluation/Create

        public ActionResult Create()
        {
            ViewBag.ID_MOD = new SelectList(db.MODULE, "ID_MOD", "LOGINPERS");
            return View();
        }

        //
        // POST: /Professeur/Evaluation/Create

        [HttpPost]
        public ActionResult Create(EVALUATION evaluation)
        {
            if (ModelState.IsValid)
            {
                db.EVALUATION.AddObject(evaluation);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ID_MOD = new SelectList(db.MODULE, "ID_MOD", "LOGINPERS", evaluation.ID_MOD);
            return View(evaluation);
        }

        //
        // GET: /Professeur/Evaluation/Edit/5

        public ActionResult Edit(int id = 0)
        {
            EVALUATION evaluation = db.EVALUATION.Single(e => e.IDEVAL == id);
            if (evaluation == null)
            {
                return HttpNotFound();
            }
            ViewBag.ID_MOD = new SelectList(db.MODULE, "ID_MOD", "LOGINPERS", evaluation.ID_MOD);
            return View(evaluation);
        }

        //
        // POST: /Professeur/Evaluation/Edit/5

        [HttpPost]
        public ActionResult Edit(EVALUATION evaluation)
        {
            if (ModelState.IsValid)
            {
                db.EVALUATION.Attach(evaluation);
                db.ObjectStateManager.ChangeObjectState(evaluation, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.ID_MOD = new SelectList(db.MODULE, "ID_MOD", "LOGINPERS", evaluation.ID_MOD);
            return View(evaluation);
        }

        //
        // GET: /Professeur/Evaluation/Delete/5

        public ActionResult Delete(int id = 0)
        {
            EVALUATION evaluation = db.EVALUATION.Single(e => e.IDEVAL == id);
            if (evaluation == null)
            {
                return HttpNotFound();
            }
            return View(evaluation);
        }

        //
        // POST: /Professeur/Evaluation/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            EVALUATION evaluation = db.EVALUATION.Single(e => e.IDEVAL == id);
            db.EVALUATION.DeleteObject(evaluation);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}